package com.learning.review;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

public class Test {
	public static void main(String[] args) {
		String path = "http://10.6.156.28:8080/DataServer/CityServlet?type=xml";
		List<String> list=getdata(path);
	    Iterator<String> iter=list.iterator();
	    while(iter.hasNext()){
	    	System.out.println(iter.next());
	    }
//		Map<String, Weather> map = getdata(path);
	}

	private static List<String> getdata(String path) {
		List<String> list = null;
		try {
			URL url = new URL(path);
			HttpURLConnection conn=(HttpURLConnection) url.openConnection();
			XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
			XmlPullParser parser=factory.newPullParser();
	
//			parser.setInput(conn.getInputStream(), "utf-8");
			int type=parser.getEventType();
			while(type!=1){
				String tag=parser.getName();
				switch (type) {
				case 0:
					list=new ArrayList<String>();
					break;

				case 2:
					if(tag.equals("name"))
						list.add(parser.nextText());
					break;
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

}
